package com.netsdk.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * OpenAPI配置类
 */
@Configuration
public class OpenApiConfig {

    private final ServerProperties serverProperties;
    private final SysInfoProperties sysInfoProperties;

    public OpenApiConfig(ServerProperties serverProperties, SysInfoProperties sysInfoProperties) {
        this.serverProperties = serverProperties;
        this.sysInfoProperties = sysInfoProperties;
    }

    @Bean
    public OpenAPI customOpenAPI() {
        String serviceUrl = "http://localhost:" + serverProperties.getPort();
        Contact contact = new Contact();
        contact.setName(sysInfoProperties.getPic());
        contact.setEmail("2366528143@qq.com");

        return new OpenAPI()
                .info(new Info()
                        .title(sysInfoProperties.getChineseName() + "后台接口文档")
                        .version(sysInfoProperties.getVersion())
                        .description(sysInfoProperties.getDescription())
                        .contact(contact)
                        .termsOfService(serviceUrl));
    }
}